﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Peak.Core;

namespace Peak.Web.Controllers.Models
{
  public class StoryModel : ModelBase
  {
    public TaskFilterModel TaskFilter { get; set; }
    public int StoryId { get; set; }
    public int CurrentSprintStoryId { get; set; }
    public string Name { get; set; }
    public string Category { get; set; }    
    public int Priority { get; set; }
    public double StoryPoints{ get;set;}
    public StoryStatus Status { get; set; }
    public string Description { get; set; }
    public string HowToDemo { get; set; }
    public int OpenTaskCount { get; set; }    
    public string SprintName { get; set; }
    public string Requester { get; set; }
    public IList<SprintStory> SprintStories { get; set; }
    
    public StoryModel() : base(()=>new StoryModelValidator())
    {      
    }

    public StoryModel(Story story) : base(() => new StoryModelValidator())
    {
      Name = story.Name;
      Category = story.Category;      
      Priority = story.Priority;
      StoryPoints = story.StoryPoints;
      Status = story.Status;
      Description = story.Description;
      HowToDemo = story.HowToDemo;
      CurrentSprintStoryId = story.CurrentSprintStory.Id;
      StoryId = story.Id;
      if (story.CurrentSprintStory.Sprint != null)
        SprintName = story.CurrentSprintStory.Sprint.Name;
      OpenTaskCount = story.OpenedTaskCount;      
      Requester = story.Requester;
      SprintStories = story.SprintStories;
    }       

    public void Update(Story story)
    {
      story.Name = Name;
      story.Category = Category;      
      story.Priority = Priority;
      story.StoryPoints = StoryPoints;      
      story.Status = Status;
      story.Description = Description;
      story.HowToDemo = HowToDemo;
      story.Requester = Requester;
    }
  }
}
